package com.chinasofti.Collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.function.Predicate;

import static com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolver.length;

public class Demo01 {
    public static void main(String[] args) {
        //method1();
        //method2();
        //method3();
        Collection<String> c = new ArrayList<>();
        //添加元素
        c.add("aaaaa");
        c.add("bbb");
        c.add("ccc");
        c.add("dddee");
        //删除长度为三的元素
//        c.removeIf(new Predicate() {
//            @Override
//            public boolean test(Object o) {
//                return ((String)o).length()==3;
//            }
//        });
        //c.removeIf((String s )->{return  s .length()==3;});
        c.removeIf((String s )->  s.length()==3);
        System.out.println("c = " + c);
    }

    private static void method3() {
        Collection<String> c = new ArrayList<>();
        //添加元素
        c.add("aaa");
        c.add("bbb");
        c.add("ccc");
        c.add("ddd");
        boolean b = c.remove("aaa");
        boolean d = c.remove("a");
        System.out.println("d = " + d);
        System.out.println("b = " + b);
        System.out.println(c);
    }

    private static void method2() {
        Collection<String> c = new ArrayList<>();
        //添加元素
        c.add("aaa");
        c.add("bbb");
        c.add("ccc");
        c.add("ddd");
        //判断集合中是否包含指定元素
        final  boolean b = c.contains("a");
        boolean b1 = c.contains("aaa");
        System.out.println("b = " + b);
        System.out.println("b1 = " + b1);
    }

    private static void method1() {
        Collection<String> c = new ArrayList<>();
        //添加元素
        c.add("hello");
        c.add("world");
        c.add("java");
        c.add("javaee");
        int size = c.size();
        System.out.println("size = " + size);
        boolean b = c.isEmpty();//集合是否为空
        System.out.println("b = " + b);
        c.clear();//清空集合
        boolean d =c.isEmpty();//集合是否为空
        System.out.println("d = " + d);
    }
}
